﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

public static class ObjectExtension
{
    /// <summary>
    /// 获取属性值
    /// </summary>
    /// <param name="t"></param>
    /// <param name="propertyName"></param>
    /// <returns></returns>
    public static string GetValue(this object t, string propertyName)
    {
        bool isValue;
        var property = t.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
        var value = property?.GetValue(t, null);
        if (value != null)
        {
            if (bool.TryParse(value.ToString(), out isValue))
            {
                value = isValue ? "1" : "0";
            }
        }
        return value != null ? value.ToString() : "";
    }
}
